package de.gwtprime.client.util;

import com.google.gwt.user.client.ui.HTML;

import de.gwtprime.shared.requestFactory.ArticleSectionProxy;
import de.gwtprime.shared.util.AppUtilsShared;

/**
 * Show a facebook like button. Only the iframe version works with GWT out of the box.
 * @author jan
 *
 */
public class FacebookWidget extends HTML{

	/**
	 * The height of the widget in pixel.
	 */
	private static int widgetWidth=130;
	
	/**
	 * The width of the widget in pixel.
	 */
	private static int widgetHeight=20;
	
	/**
	 * Show facebook faces.
	 */
	private static boolean showFaces = true;
	
	/**
	 * The application id.
	 */
	private static String appId = "545100238887069";
	
	public FacebookWidget(){
		this(null);
	}
	public FacebookWidget(ArticleSectionProxy entity) {
		super(getIFrameVersion(entity));
	}
	
	public static String getIFrameVersion(ArticleSectionProxy entity){
		

		String s = "<iframe src='//www.facebook.com/plugins/like.php?href="+(entity != null ? AppUtilsShared.convertToFacebookUrl(entity) : AppUtilsShared.DOMAIN_PROD)+
				"&amp;width="+ widgetWidth +
				"&amp;height="+widgetHeight+
				"&amp;colorscheme=light&amp;layout=button_count&amp;action=like&amp;show_faces="+showFaces+
				"&amp;send=false&amp;appId="+appId+"'"+
				"scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:"+widgetWidth+"px; "+
				"height:"+widgetHeight+"px;' " +
				"allowTransparency='true'></iframe>";
		
		return s;
	}
	
	
	
	/**
	 * The HTML5 version needs the script to be loaded in the host page first
	 * @param entity
	 * @return
	 */
	public static String getHTML5Version(ArticleSectionProxy entity){
		
		String s = "<div class=\"fb-like\" data-href=\""+AppUtilsShared.convertToFacebookUrl(entity)+"\" data-width=\"300\" data-layout=\"button_count\" data-show-faces=\"true\" data-send=\"false\"></div>";
		
		return s;
	}
	
}
